home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#40 (Jan 89)
/
Bezier Application
/
Skeleton.c
< prev
Wrap
C/C++ Source or Header
|
1988-04-12
|
3KB
|
245 lines
/*
** Skeleton.c -- A bare-bones skeleton.
**
** This has been hacked up to demonstrate Bezier curves. Other
** than the tracking technique, there's little here of interest.
**
** David W. Smith
*/
#include "QuickDraw.h"
#include "MacTypes.h"
#include "FontMgr.h"
#include "WindowMgr.h"
#include "MenuMgr.h"
#include "TextEdit.h"
#include "DialogMgr.h"
#include "EventMgr.h"
#include "DeskMgr.h"
#include "FileMgr.h"
#include "ToolboxUtil.h"
#include "ControlMgr.h"
WindowRecord wRecord;
WindowPtr myWindow;
/*
* main
*
* Initialize the world, then handle events until told to quit.
*/
main()
{
InitGraf(&thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
InitDialogs(0L);
InitCursor();
MaxApplZone();
SetupMenus();
SetupWindow();
SetupBezier();
while ( DoEvent(everyEvent) )
;
}
/*
* SetupMenus
*
* For the purpose of this demo, we get somewhat non-standard and
* use no menus. Closing the window quits.
*/
SetupMenus()
{
DrawMenuBar();
}
/*
* SetupWindow
*
* Setup the window for the Bezier demo.
*/
SetupWindow()
{
Rect bounds;
bounds = WMgrPort->portBits.bounds;
bounds.top += 36;
InsetRect(&bounds, 5, 5);
myWindow = NewWindow(&wRecord, &bounds, "\pBezier Sampler - Click and Drag",
1, noGrowDocProc, 0L, 1, 0L);
SetPort(myWindow);
}
/*
* DoEvent
*
* Generic event handling.
*/
DoEvent(eventMask)
int eventMask;
{
EventRecord myEvent;
WindowPtr whichWindow;
Rect r;
SystemTask();
if ( GetNextEvent(eventMask, &myEvent) )
{
switch ( myEvent.what )
{
case mouseDown:
switch ( FindWindow( myEvent.where, &whichWindow ) )
{
case inDesk:
break;
case inGoAway:
if ( TrackGoAway(myWindow, myEvent.where) )
{
HideWindow(myWindow);
return (0);
}
break;
case inMenuBar:
return (DoCommand(MenuSelect(myEvent.where)));
case inSysWindow:
SystemClick(&myEvent, whichWindow);
break;
case inDrag:
break;
case inGrow:
break;
case inContent:
DoContent(&myEvent);
break;
default:
break;;
}
break;
case keyDown:
case autoKey:
break;
case activateEvt:
break;
case updateEvt:
DoUpdate();
break;
default:
break;
}
}
return(1);
}
/*
* DoCommand
*
* Command handling would normally go here.
*/
DoCommand(mResult)
long mResult;
{
int theItem, temp;
Str255 name;
WindowPeek wPtr;
theItem = LoWord(mResult);
switch ( HiWord(mResult) )
{
}
HiliteMenu(0);
return(1);
}
/*
* DoUpdate
*
* Generic update handler.
*/
DoUpdate()
{
BeginUpdate(myWindow);
Draw();
EndUpdate(myWindow);
}
/*
* DoContent
*
* Handle mouse-downs in the content area by asking the application to
* produce a tracker object. We then call the tracker repeatedly to
* track the mouse.
*
* This technique came originally (as nearly as I can tell) from Xerox,
* and is used in a modified form in MacApp.
*/
struct Tracker
{
int (*Track)();
};
int
DoContent(pEvent)
EventRecord *pEvent;
{
struct Tracker *GetTracker();
struct Tracker *t;
Point point, newPoint;
point = pEvent->where;
GlobalToLocal(&point);
t = GetTracker(point);
if ( t )
{
(*t->Track)(t, point, 1);
while ( StillDown() )
{
GetMouse(&newPoint);
if ( newPoint.h != point.h || newPoint.v != point.v )
{
point = newPoint;
(*t->Track)(t, point, 2);
}
}
(*t->Track)(t, point, 3);
}
}